package tools

import (
	"bytes"
	"compress/gzip"
	"fmt"
	"github.com/golang/protobuf/proto"
)

//message GZipMsg {
//required bytes data = 1;
//required int32 serverType = 2;
//required int32 msgId = 3;
//}

func GetGZipMsg(msg proto.Message, serverType, msgId int32) {
	testMsgData, err := proto.Marshal(msg)
	if err != nil {
		return
	}

	//resultMsg := &common.GZipMsg{
	//	ServerType: proto.Int32(serverType),
	//	MsgId:      proto.Int32(msgId),
	//}

	var b bytes.Buffer
	w := gzip.NewWriter(&b)
	defer w.Close()

	w.Write(testMsgData)
	w.Flush()

	//resultMsg.Data = b.Bytes()
	fmt.Printf("GetGZipMsg msg: %T, save: %0.5f\n", msg, 1-float64(len(b.Bytes()))/float64(len(testMsgData)))

	//return resultMsg
	return
}
